package com.westvalley.workflow.action.nc;

import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.RequestInfo;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Db;
import com.westvalley.common.action.BasisWe8Action;
import com.westvalley.common.action.result.ActionResult;
import com.westvalley.common.action.util.WorkFlowActionUtil;
import com.westvalley.common.result.JsonResult;
import com.westvalley.service.api.nc.NcApproveService;

public class L001ArchivingAction extends BasisWe8Action{

	@Override
	protected ActionResult executeResult(RequestInfo requestInfo) {
		ActionResult result = ActionResult.me(requestInfo);
		MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
		String unitcode = WorkFlowActionUtil.getFieldValue(mainTableInfo, "financeunitcode");
		String billno = WorkFlowActionUtil.getFieldValue(mainTableInfo, "NCxgdh");
		JsonResult jsonResult = NcApproveService.me(unitcode, billno, "Y").getJsonResult();
		if(!jsonResult.isFlag())
			throw new RuntimeException(jsonResult.getMsg());
		else{
			JSONObject resultJson = (JSONObject) jsonResult.getResult();
			Db.update("UPDATE "+mainTableName+" SET pingzh = ? WHERE requestId = ?", resultJson.getString("message"),requestInfo.getRequestid());
		}
		return result;
	}

}
